package checklist.service;

import java.util.List;

import checklist.db.CheckDAO;
import checklist.db.DAOFactorySingleton;
import checklist.db.UserCheckDAO;
import checklist.db.UserDAO;
import checklist.entity.Check;
import checklist.entity.User;
import checklist.entity.UserCheck;
import checklist.vo.CheckVO;
import checklist.vo.UserVO;

public class UserService {
	UserDAO userDAO;
	UserCheckDAO userCheckDAO;
	CheckDAO checkDAO;
	
	public UserService() {
		userDAO = DAOFactorySingleton.instance(UserDAO.class);
		userCheckDAO = DAOFactorySingleton.instance(UserCheckDAO.class);
		checkDAO = DAOFactorySingleton.instance(CheckDAO.class); 
	}
	
	public UserVO createNew(String name) {
		User user = new User();
		user.setName(name);
		userDAO.save(user);
		return user;		
	}
	
	public void addCheck(UserVO userVO, CheckVO checkVO) {
		UserCheck userCheck = new UserCheck();
		
		userCheck.setUser(userDAO.search(userVO.getId()));
		userCheck.setCheck(checkDAO.search(checkVO.getId()));
		userCheckDAO.save(userCheck);
	}
}
